package hz.mobileproject.pda.ui.activity.work;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.Log;
import android.view.View;


import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.vivian.timelineitemdecoration.itemdecoration.DotItemDecoration;
import com.vivian.timelineitemdecoration.itemdecoration.SpanIndexListener;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import cn.droidlover.xdroidmvp.mvp.XActivity;
import cn.droidlover.xdroidmvp.router.Router;
import hz.mobileproject.pda.R;
import hz.mobileproject.pda.entity.request.Request_rollCall_queryRcLog;
import hz.mobileproject.pda.entity.response.Response_QueryCallRoll;
import hz.mobileproject.pda.presenter.PCalroll_query;
import hz.mobileproject.pda.ui.adapter.DotTimeLineAdapter;

public class DotTimeLineActivity extends XActivity<PCalroll_query> {
    RecyclerView mRecyclerView;

    List<Response_QueryCallRoll> mList = new ArrayList<>();
    DotTimeLineAdapter mAdapter;
    DotItemDecoration mItemDecoration;


    private SPUtils spUtils_cusNumber;
    private Gson gson;
    private String callroll_data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
        mItemDecoration = new DotItemDecoration
                .Builder(this)
                .setOrientation(DotItemDecoration.VERTICAL)//if you want a horizontal item decoration,remember to set horizontal orientation to your LayoutManager
                .setItemStyle(DotItemDecoration.STYLE_DRAW)
                .setTopDistance(20)//dp
                .setItemInterVal(10)//dp
                .setItemPaddingLeft(20)//default value equals to item interval value
                .setItemPaddingRight(20)//default value equals to item interval value
                .setDotColor(Color.WHITE)
                .setDotRadius(2)//dp
//                .setDotPaddingTop(0)
//                .setDotInItemOrientationCenter(false)//set true if you want the dot align center
                .setLineColor(Color.RED)
                .setLineWidth(1)//dp
                .setEndText("END")
                .setTextColor(Color.WHITE)
                .setTextSize(10)//sp
                .setDotPaddingText(2)//dp.The distance between the last dot and the end text
                .setBottomDistance(40)//you can add a distance to make bottom line longer
                .create();
        mItemDecoration.setSpanIndexListener(new SpanIndexListener() {
            @Override
            public void onSpanIndexChange(View view, int spanIndex) {
                Log.i("Info","view:"+view+"  span:"+spanIndex);
                view.setBackgroundResource(spanIndex == 0 ? R.drawable.pop_left : R.drawable.pop_right);
            }
        });
        mRecyclerView.addItemDecoration(mItemDecoration);



        mAdapter = new DotTimeLineAdapter(this, mList);
        mRecyclerView.setAdapter(mAdapter);
    }
    public static void launch(Activity activity ) {
        Router.newIntent(activity)
                .to(DotTimeLineActivity.class)
                .launch();


    }

    @Override
    public void onWidgetClick(View view) {

    }

    @Override
    public void initData(Bundle savedInstanceState) {
        spUtils_cusNumber = SPUtils.getInstance("app_login");
        gson= new Gson();
        //获取配置
        Request_rollCall_queryRcLog callroll_loadCnf = new Request_rollCall_queryRcLog();
        String nowTime = TimeUtils.getNowString(new SimpleDateFormat("yyyy-MM-dd"));
        callroll_loadCnf.setCusNumber(spUtils_cusNumber.getString("cusnumber"));
        callroll_loadCnf.setQueryTime(nowTime);
        callroll_loadCnf.setQueryDept("65");
        callroll_data = gson.toJson(callroll_loadCnf);

        getP().getData(callroll_data, 10);
    }

    @Override
    public int getLayoutId() {
        return R.layout.dot_timeline_layout;
    }

    @Override
    public PCalroll_query newP() {
        return new PCalroll_query();
    }

    public void respnose_data(String data_json){
        try {
            List<Response_QueryCallRoll> loadSubPrisons = gson.fromJson(data_json, new TypeToken<List<Response_QueryCallRoll>>(){}.getType());
            mAdapter.setList(loadSubPrisons);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

}
